using System.Collections.Generic;
using System.Linq;
using Game.Level;
using Game.Plugin;
using Game.Plugin.Parse;

namespace DebugPlugin
{
    public class QueryPlugin : AbstractPlugin
    {
        readonly GameLevels _Levels;

        public QueryPlugin(IGamePlugin parent, GameLevels levels)
            : base(parent, "levels")
        {
            _Levels = levels;
        }

        public override ICodeObject Parse(
            string token, 
            ParserContext context)
        {
            IExpression e = new QueryExpression(_Levels);
            context.Stack.Push(e);
            return e;
        }
    }

    class QueryExpression : IExpression
    {
        readonly GameLevels _Levels;

        public QueryExpression(GameLevels levels)
        {
            _Levels = levels;
        }

        public object Interpret(Dictionary<string, ICodeObject> variables)
        {
            return _Levels.Aggregate(
                "", (current, e) => current + (e.Name + " "));
        }
    }
}